﻿<UserControl x:Class="MediaBrowser.Gui.Views.PagePicturesView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:MediaBrowser.Gui.ViewModels"
    xmlns:ScrollControl="clr-namespace:MediaBrowser.CustomControls.ScrollControl;assembly=MediaBrowser.CustomControls"
    xmlns:Panels="clr-namespace:MediaBrowser.CustomControls.Panels;assembly=MediaBrowser.CustomControls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:Converters="clr-namespace:MediaBrowser.Gui.Converters"
    xmlns:local="clr-namespace:MediaBrowser.Gui.Views"
    xmlns:EffectsLib="clr-namespace:EffectsLib;assembly=EffectsLib" 
    xmlns:julmar="http://www.julmar.com/wpfhelpers"
    mc:Ignorable="d" d:DesignWidth="768" d:DesignHeight="1024">

    <!--<UserControl.DataContext>
        <Binding Mode="OneWay" Path="Pictures" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>-->

    <UserControl.Resources>

        <ViewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>

        <local:UserCtrlZoomPicture x:Key="userCtrlZoomPicture"/>
        <local:UserCtrlDataPictures x:Key="userCtrlDataPictures"/>
                
        <Storyboard x:Key="ShowCtrlPictures" AccelerationRatio="0.5" DecelerationRatio="0.5" >
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(Panels:FlipPanel.IsUILoaded)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:00.1" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="scrollerControl" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:00.1" Value="False"/>
            </BooleanAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="False"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="scrollerControl" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="stackPanel" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
        </Storyboard>

        <Storyboard x:Key="HideCtrlPictures" AccelerationRatio="0.5" DecelerationRatio="0.5" >
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(Panels:FlipPanel.IsUILoaded)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:00.1" Value="False"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="flipPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="scrollerControl" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="scrollerControl" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="stackPanel" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
        </Storyboard>

    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="ScrollControl:ScrollerControl.OnItemsSelected" SourceName="scrollerControl">
            <BeginStoryboard Storyboard="{StaticResource ShowCtrlPictures}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Panels:FlipPanel.OnClose" SourceName="flipPanel">
            <BeginStoryboard Storyboard="{StaticResource HideCtrlPictures}"/>
        </EventTrigger>
    </UserControl.Triggers>


    <Grid DataContext="{Binding Mode=OneWay, Path=Pictures, Source={StaticResource Locator}}" x:Name="gridMain">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="stackPanel" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,10">
            <StackPanel.Effect>
                <EffectsLib:BrightContrastEffect/>
            </StackPanel.Effect>
            <TextBox x:Name="tbSearch" Width="150" Height="20" />
            <Label Content="(" Margin="10,0,0,0" VerticalAlignment="Center" />
            <Label Content="{Binding ElementName=scrollerControl, Path=Count}" VerticalAlignment="Center"/>
            <Label Content=")" VerticalAlignment="Center"/>
            <StackPanel Margin="10,0,0,0" Orientation="Vertical" >
                <RadioButton x:Name="rdAll" Checked="rd_Checked">Tous</RadioButton>
                <RadioButton x:Name="rdWithoutDescription" Checked="rd_Checked">Sans Description</RadioButton>
                <RadioButton x:Name="rdWithDescription" Checked="rd_Checked">Avec Description</RadioButton>
            </StackPanel>
        </StackPanel>
        <ScrollControl:ScrollerControl x:Name="scrollerControl"
                                       Grid.Row="1"                                       
                                       ItemsSource="{Binding Medias}" MemberBinding="UrlImage"
                                       SelectCommand="{Binding SelectCurrentCommand}"
                                       Filter="{Binding ElementName=tbSearch, Path=Text}"
                                       MemberFilterBinding="Name,Description"
                                       Visibility="Visible">
            <julmar:EventCommander.Mappings>
                <julmar:CommandEvent Command="{Binding ItemsAddedCommand}" 
                                     CommandParameter="{Binding ElementName=scrollerControl, Path=CurrentItemDrop}" 
                                     Event="OnItemsDrop"/>
                <julmar:CommandEvent Command="{Binding ItemsDeleteCommand}" 
                                     Event="OnItemsDelete"/>
            </julmar:EventCommander.Mappings>
            <ScrollControl:ScrollerControl.Effect>
                <EffectsLib:BrightContrastEffect/>
            </ScrollControl:ScrollerControl.Effect>
        </ScrollControl:ScrollerControl>

        <Panels:FlipPanel x:Name="flipPanel" Grid.Row="1" 
                                       FrontTemplate="{StaticResource userCtrlZoomPicture}"
                                       BackTemplate="{StaticResource userCtrlDataPictures}"
                                       IsUILoaded="False"
                                       RenderTransformOrigin="0.5,0.5"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center">
            <Panels:FlipPanel.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="0" ScaleY="0"/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Panels:FlipPanel.RenderTransform>
            <Panels:FlipPanel.Effect>
                <EffectsLib:BrightContrastEffect/>
            </Panels:FlipPanel.Effect>
        </Panels:FlipPanel>
    </Grid>
</UserControl>
